home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / ModifyDIZ / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  5KB  |  231 lines

  1. /*
  2.  
  3.   ModifyDIZ
  4.   =========
  5.  
  6.  
  7.   This door displays the .DIZ on the screen
  8.   the user is then asked
  9.  
  10.   1) Use this DIZ
  11.   2) Enter New DIZ
  12.   3) Modify DIZ
  13.  
  14.   Pressing return defaults to option 1.
  15.  
  16.   Options
  17.   =======
  18.  
  19.     N_ND->ActiveDoor->SystemOptions
  20.     -------------------------------
  21.  
  22.     none
  23.  
  24.     Door Options (Command Line)
  25.     ---------------------------
  26.  
  27. 2   <filename>
  28.  
  29. 3   <workdir>
  30.  
  31. 4   <playpen dir>
  32.  
  33. 5   <filename without .extension>
  34.  
  35. 6   <.extension without filename and without the .>
  36.  
  37.     Note: Hey, I really couldn't think of any other settings that might be usefull..
  38.     you can even write a damn AmigaDOS script to extract file_id's with all those
  39.     parameters! hehehe
  40.  
  41.  
  42. */
  43.  
  44.  
  45. #include <exec/types.h>
  46. #include <exec/memory.h>
  47. #include <dos/dos.h>
  48. #include <clib/exec_protos.h>
  49. #include <clib/dos_protos.h>
  50. #include <clib/alib_protos.h>
  51.  
  52. #include <stdlib.h>
  53. #include <string.h>
  54. #include <stdio.h>
  55. #include <ctype.h>
  56. #include <time.h>
  57.  
  58.  
  59. #ifdef __SASC
  60. int CXBRK(void) { return(0); }
  61. int _CXBRK(void) { return(0); }
  62. void chkabort(void) {}
  63. #endif
  64.  
  65. #include <HBBS/ANSI_Codes.h>
  66. #include <HBBS/Defines.h>
  67. #include <HBBS/types.h>
  68. #include <HBBS/structures.h>
  69. #include <HBBS/hbbscommon_protos.h>
  70. #include <HBBS/hbbscommon_pragmas.h>
  71. #include <HBBS/Hbbsnode_protos.h>
  72. #include <HBBS/Hbbsnode_pragmas.h>
  73. #include <HBBS/release.h>
  74. char *versionstr="$VER: ModifyDIZ "RELEASE_STR;
  75.  
  76. struct Library *HBBSCommonBase=NULL;
  77. struct Library *HBBSNodeBase=NULL;
  78.  
  79. struct BBSGlobalData *BBSGlobal=NULL;
  80. struct NodeData *N_ND=NULL;
  81. int N_NodeNum=-1;
  82. char outstr[1024]; // temp string for displaying text..
  83. char filename[1024]; // temp string for displaying text..
  84.  
  85.   struct List *FileID=NULL;
  86.  
  87. static VOID cleanup(ULONG num)
  88. {
  89.   if (HBBSNodeBase)
  90.   {
  91.     HBBS_CleanUpDoor();
  92.     CloseLibrary (HBBSNodeBase);
  93.   }
  94.  
  95.   if (HBBSCommonBase)
  96.   {
  97.     HBBS_CleanUpCommon();
  98.     CloseLibrary (HBBSCommonBase);
  99.   }
  100.  
  101.   if (num) printf("Door Error = %d\n",num);
  102.  
  103.   exit(0);
  104. }
  105.  
  106. static VOID init(char *name)
  107. {
  108.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  109.   {
  110.     cleanup(1);
  111.   }
  112.  
  113.   if (!(HBBS_InitCommon()))
  114.   {
  115.     cleanup(2);
  116.   }
  117.  
  118.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  119.   {
  120.     cleanup(3);
  121.   }
  122.  
  123.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  124.   {
  125.     cleanup(4);
  126.   }
  127.   SetProgramName(name);
  128. }
  129.  
  130. void DisplayDIZ( void )
  131. {
  132.   struct Node *node;
  133.  
  134.   DOOR_WriteText(ANSI_RESET ANSI_FG_YELLOW "  +---------------------------------------------+\r\n" ANSI_FG_WHITE);
  135.   for (node = FileID->lh_Head ; node->ln_Succ ; node =node->ln_Succ)
  136.   {
  137. //    if (strlen(node->ln_Name)>LEN_DIZWIDTH) node->ln_Name[LEN_DIZWIDTH]=0;
  138.     sprintf(outstr,"   %s\r\n",node->ln_Name);
  139.     DOOR_WriteText(outstr);
  140.   }
  141.   DOOR_WriteText(ANSI_RESET ANSI_FG_YELLOW "  +---------------------------------------------+\r\n" ANSI_FG_WHITE);
  142. }
  143.  
  144. void EditDIZ( void )
  145. {
  146.   V_SMALLNUM Lines;
  147.   V_BOOL Done=FALSE;
  148.  
  149.   Lines=N_ND->MaxDIZLines;
  150.   sprintf(outstr,"please enter upto %d lines to describe this file\r\n",N_ND->MaxDIZLines);
  151.   DOOR_WriteText(ANSI_RESET ANSI_FG_YELLOW "  +---------------------------------------------+\r\n" ANSI_FG_WHITE);
  152.   while ((N_ND->OnlineStatus==OS_ONLINE) && (Lines>0) && (!Done))
  153.   {
  154.     DOOR_WriteText(ANSI_FG_YELLOW "  >\033[45C<\033[46D" ANSI_FG_WHITE);
  155.     DOOR_GetLine(GL_NODISTURB|GL_EDIT|GL_DISPLAY|GL_HISTORY,'\0',LEN_DIZWIDTH,0,NULL);
  156.     if (N_ND->OnlineStatus==OS_ONLINE)
  157.     {
  158.       if (N_ND->CurrentLine[0]==0) // blank line..
  159.       {
  160.         Done=TRUE; // finished entering fileid
  161.         DOOR_WriteText("\033[A"); //move up 1 line
  162.       }
  163.       else
  164.       {
  165.         NewStrNode(N_ND->CurrentLine,FileID); // add line to the list
  166.         Lines--;
  167.       }
  168.     }
  169.   }
  170.   DOOR_WriteText(ANSI_RESET ANSI_FG_YELLOW "  +---------------------------------------------+\r\n" ANSI_FG_WHITE);
  171. }
  172.  
  173. void SaveID( void ) // *C* add error checking. / create new routine and call it HBBS_SaveFile()
  174. {
  175.   HBBS_SaveFile(filename,FileID);
  176. }
  177.  
  178. void DoorMain(int argc,char *argv[])
  179. {
  180.   DOOR_WriteText("\r\n-=[  Hydra ModifyDIZ V1.1  ]=- ========= -=[  (C) 1996 Deluxe Software Ltd  ]=-\r\n\r\n");
  181.  
  182.   if (argc==6 || argc==7)
  183.   {
  184.     sprintf(outstr,"Displaying DIZ for file %-13s\r\n",argv[2]);
  185.     DOOR_WriteText(outstr);
  186.     sprintf(filename,"%sWork/%s.DIZ",N_ND->NodeLocation,argv[2]);
  187.     if (!(FileID=HBBS_LoadFile(filename)))
  188.     {
  189.       if (FileID=HBBS_CreateList())
  190.       {
  191.         DOOR_WriteText("No FileID contained within uploaded file, please enter a new one\r\n");
  192.         EditDIZ();
  193.       }
  194.     }
  195.     else
  196.     {
  197.       DisplayDIZ();
  198.     }
  199.     if (FileID)
  200.     {
  201.       // Menu Here...
  202.     }
  203.   }
  204.   else DOOR_WriteText(ANSI_RESET ANSI_FG_RED "Invalid Door Options!\r\n");
  205.  
  206.   if (FileID)
  207.   {
  208.     SaveID();
  209.     FreeStrList(FileID);
  210.   }
  211. }
  212.  
  213. int main(int argc,char *argv[])
  214. {
  215.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  216.   {
  217.     printf("Invalid/No Paramaters for door!\n");
  218.     exit (20);
  219.   }
  220.   init("ModifyDIZ");
  221.  
  222.   if (BBSGlobal=HBBS_GimmeBBS())
  223.   {
  224.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  225.     {
  226.       DoorMain(argc,argv);
  227.     }
  228.   }
  229.   cleanup(0);
  230. }
  231.